package com.itheima.zzyl.controller;

import com.itheima.zzyl.pojo.NursingProject;
import com.itheima.zzyl.pojo.PageResult;
import com.itheima.zzyl.pojo.Result;
import com.itheima.zzyl.service.NursingProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/orders/project")
public class NursingProjectController {
    @Autowired
    @Qualifier("nursingProjectService")
    private NursingProjectService nursingProjectService;

    @Autowired
    @Qualifier(value = "redisTemplate")
    private RedisTemplate redisTemplate;
    @Cacheable(value = "nursingProjectCache", key = "#pageSize +'_'+ #pageNum")
    @GetMapping("/page")
    public Result<PageResult<NursingProject>> list(
            @RequestParam("userId") Integer userId,
            @RequestParam("pageSize") Integer pageNum,
            @RequestParam("pageNum") Integer pageSize
    ) {
        if (userId == null) {
            System.out.println(userId);
        }
        Result<PageResult<NursingProject>> list = nursingProjectService.list(pageSize, pageNum);
        return list;
    }

    @GetMapping("/{id}")
    public Result<NursingProject> getById(@PathVariable Integer id) {
        NursingProject nursingProject = nursingProjectService.getById(id);
        return Result.success(nursingProject);
    }
}
